﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using ComLib.ConfigService;
using ComLib.ComFun;
using System.Drawing;
using ComLib.ComType;
using System.IO;
using System.Reflection;

namespace IPCPages
{
    /// <summary>
    /// 回执打印参数
    /// </summary>
    [XmlRootAttribute("TakeReceiptOption", Namespace = "IPCPages", IsNullable = false)]
    public class TakeReceiptOption : XmlSerializeBase
    {
        [XmlIgnore]
        public override string ConfigDirectory
        {
            get
            {
                string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
                directory = directory.Substring(6);
                return directory;
            }
        }

        public TakeReceiptOption()
        {

        }

        /// <summary>
        /// 回执打印机名称
        /// </summary>
        private string _printer = "POS80";
        public string Printer
        {
            get { return _printer; }
            set { _printer = value; }
        }

        /// <summary>
        /// 使用单位
        /// </summary>
        private string _department = "公安局出入境";
        public string Department
        {
            get { return _department; }
            set { _department = value; }
        }

        public override bool Serialize()
        {
            return Serializer.SaveToXml(ConfigFilePath, this);
        }
     
        public override bool Load()
        {
            TakeReceiptOption obj = (TakeReceiptOption)Serializer.LoadFromXml(ConfigFilePath, this.GetType());
            if (obj != null)
            {
                this._printer = obj._printer;
                this._department = obj.Department;
                this._nVer = obj._nVer;   
                return true;
            }
            else
            {
                ErrorMessage = Serializer.Message;
                return false;
            }
        }

        public override string ToString()
        {       
            StringBuilder builder = new StringBuilder("回执打印参数: ");
            FillFieldValueStringDelegate FillString =
              (string field, object val) =>
              {
                  builder.Append("[");
                  builder.Append(field);
                  builder.Append("]: ");
                  builder.Append(val.ToString() + "; ");
              };
            FillString("打印机名称:", _printer);
            FillString("使用部门:", _department);           
            return builder.ToString();
        }
    }
}
